package cn.yangliu.gennerator;

import cn.yangliu.source.XmlSource;
import cn.yangliu.tools.FileUtils;

import java.io.InputStream;

public class XmlGenerator implements Generator<XmlSource> {

    private String t_xml;

    public XmlGenerator() {
        try (InputStream is =this.getClass().getClassLoader().getResourceAsStream("templates/t_mapper.xml")){
            t_xml = FileUtils.read(is,true);
        }catch (Exception e){
            throw new RuntimeException(e.getMessage(),e);
        }
    }

    @Override
    public void generate(XmlSource source) {
        String xmlCode = t_xml.replace("","");
        xmlCode = xmlCode.replace("[mapper-class-full-name]",source.getMapperFullName());
        FileUtils.output(xmlCode,source.getFilepath(),source.getFilename());
    }
}
